﻿/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       App_Input_RoomStatusSrhForm
 * 类型：       房态信息查询
 * 功能说明：   检索
 * 作者：       谈震鸣
 * 创建日期：   2007/08/22
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OWC11;
using Shpm.App.Master.Bean;
using Shpm.System;
using Shpm.App.Search.Bean;
using Shpm.App.Search.Dao;
using Shpm.App.Commons.Utils;
using Shpm.System.Db;
public partial class App_Input_RoomStatusSrhForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {
            if (string.IsNullOrEmpty(Request.QueryString["buildingNo"]))
            {
                this.Table1.Visible = false;
                this.Table2.Visible = false;
                this.Table3.Visible = false;
                hidBuildingNo.Value = Convert.ToString(Context.Items["buildingNo"]);
                this.roomTable.Visible = false;
            }
            else
            {
                int bNo = Convert.ToInt32(Request.QueryString["buildingNo"]);
                hidBuildingNo.Value = bNo.ToString();
                this.bNo.InnerText = Convert.ToString(Request.QueryString["buildingNo"]);
                SetBuilNum(hidBuildingNo.Value);
            }
        }

        if (!"".Equals(hidBuildingNo.Value))
        {
                try
                {
                    int no = int.Parse(hidBuildingNo.Value);
                    if( no == 1|| no == 2)
                    {
                        this.Table1.Visible = true;
                        this.Table2.Visible = false;
                        this.Table3.Visible = false;
                        SetColor(hidBuildingNo.Value, this.Table1);
                    }
                    else if (no == 3 || no == 4)
                    {
                        this.Table1.Visible = false;
                        this.Table2.Visible = true;
                        this.Table3.Visible = false;
                        SetColor(hidBuildingNo.Value, this.Table2);
                    }
                    else if ( 5<=no && no<=9 )
                    {
                        this.Table1.Visible = false;
                        this.Table2.Visible = false;
                        this.Table3.Visible = true;
                        SetColor(hidBuildingNo.Value, this.Table3);
                    }
                    else 
                    {
                        this.roomTable.Visible = false;
                    }
                }
                catch(Exception es)
                {
                    throw new DataAccessException(es);
                }
        }

        GetImgCnt();
    }

    private void SetBuilNum(string bNo)
    {
        SalesInfoDao dao = new SalesInfoDao();
        SalesInfoBean salesInfoBean = new SalesInfoBean();
        salesInfoBean.BuildingNo = bNo;
        IList roomNumList = dao.FindBuildNum(salesInfoBean);
        int count = 0;
        if (roomNumList.Count>0)
        {
            for (int i = 0; i < roomNumList.Count;i++ )
            {
                salesInfoBean = (SalesInfoBean)roomNumList[i];
                switch (salesInfoBean.Model)
                {
                    case "A":
                        this.numA.InnerText = salesInfoBean.SNo3.ToString();
                        count += salesInfoBean.SNo3;
                        break;
                    case "B":
                        this.numB.InnerText = salesInfoBean.SNo3.ToString();
                        count += salesInfoBean.SNo3;
                        break;
                    case "C":
                        this.numC.InnerText = salesInfoBean.SNo3.ToString();
                        count += salesInfoBean.SNo3;
                        break;
                    case "D":
                        this.numD.InnerText = salesInfoBean.SNo3.ToString();
                        count += salesInfoBean.SNo3;
                        break;
                }
            }
            this.count.InnerText = count.ToString();
        }
    }


    private void SetColor(string bNo,Table table)
    {
        SalesInfoDao dao = new SalesInfoDao();
        SalesInfoBean salesInfoBean = new SalesInfoBean();
        salesInfoBean.BuildingNo = bNo;
        IList roomList = dao.FindBuildDetail(salesInfoBean);
        IList roomPersonList = dao.FindRoomPerson(salesInfoBean);

        System.Drawing.ColorConverter cc = new System.Drawing.ColorConverter();
        string roomNo = "";

        if (roomList != null && roomList.Count > 0)
        {
            for (int i = 1; i < table.Rows.Count; i++)
            {
                TableRow r = table.Rows[i];
                for (int j = 1; j < r.Cells.Count; j++)
                {
                    TableCell c = r.Cells[j];
                    if (!"&nbsp;".Equals(c.Text))
                    {
                        roomNo = string.Format("{0:00}", int.Parse(bNo)) + string.Format("{0:0000}", int.Parse(c.Text));
                        IEnumerator iem = roomList.GetEnumerator();

                        IEnumerator iem2 = roomPersonList.GetEnumerator();

                        SalesInfoBean bean = null;
                        LinkButton lb = new LinkButton();
                        lb.Text = c.Text;
                        lb.Command += new CommandEventHandler(this.LinkButton_Command);
                        string tip = "";
                        //lb.ToolTip = "xxx(yd) \n yyy(fd)";

                        ////
                        while (iem2.MoveNext())
                        {
                            bean = (SalesInfoBean)iem2.Current;
                            if (roomNo.Equals(bean.ApartmentNo))
                            {
                                //lb.CommandName = bean.StatusNo;
                                //tip += bean.NameC;
                                switch (bean.StatusNo)
                                {
                                    case "1":
                                    case "01":
                                        tip += "销售员：" + bean.EmployeeName + "--" + "客户：" + bean.NameC + "(意向)\n";

                                        break;

                                    case "3":
                                    case "03":
                                        tip += "销售员：" + bean.EmployeeName + "--" + "客户：" + bean.NameC + "(订付)\n";
                                        break;
                                  
                                    case "4":
                                    case "04":
                                        tip += "销售员：" + bean.EmployeeName + "--" + "客户：" + bean.NameC + "(入住)\n";
                                        break;
                                }
                            }
                        }
                        lb.ToolTip = tip;
                        //

                        while (iem.MoveNext())
                        {
                            bean = (SalesInfoBean)iem.Current;
                            if (roomNo.Equals(bean.ApartmentNo))
                            {
                                switch (bean.StatusNo)
                                {
                                    case "1":
                                    case "01":
                                        /*存在意向的*/
                                        if (!string.IsNullOrEmpty(bean.SaleApartmentNo))
                                        {
                                            lb.CommandName = "意向";
                                            c.BackColor = (System.Drawing.
                                          Color)cc.ConvertFromString("#ff0000");
                                        }
                                        else 
                                        {
                                            lb.CommandName = "待租";
                                            c.BackColor = (System.Drawing.
                                          Color)cc.ConvertFromString("#9acd32");
                                        }

                                        break;
                                    case "2":
                                    case "02":
                                        lb.CommandName = "付订";
                                        c.BackColor = (System.Drawing.
                                            Color)cc.ConvertFromString("#ba55d3");
                                        break;
                                  
                                    case "3":
                                    case "03":
                                        lb.CommandName = "入住";
                                        c.BackColor = (System.Drawing.
                                            Color)cc.ConvertFromString("#a9a9a9");
                                        break;
                                }
                                c.Controls.Add(lb);
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    protected void LinkButton_Command(object sender, CommandEventArgs e)
    {
        Context.Items["STATUS_NO"] = (sender as LinkButton).CommandName;
        Context.Items["APARTMENT_NO"] = string.Format("{0:00}", int.Parse(hidBuildingNo.Value)) + string.Format("{0:0000}", int.Parse((sender as LinkButton).Text));
         Context.Items["buildingNo"] = hidBuildingNo.Value;
        // Context.Items["ParamPageIndex"] = Convert.ToString(GridView1.PageIndex);
         //dataBean.Model = ((Label)row.FindControl("Label4")).Text;
         //Context.Items["ROOM_INFO"]=dataBean;
         // Server.Transfer("~/App/Search/RoomDetailsInfoForm.aspx", true);
         ControllerUtils.Transfer(this.Context, "~/App/Search/RoomDetailsInfoForm.aspx", true);
    }
    
    /*
    *名称： SetImage
    *功能： 生成饼图
    *参数： i,j,k
    *返回： 无
    *说明： 无
    */
    private void SetImage(int i, int j, int l, int k)
    {
        //存放月
        string[] MonNum = new string[] { "付订率", "待租率", "入住率", "意向率" };
        //存放数据
        string[] MonCount = new string[] { i.ToString(), j.ToString(), l.ToString(),k.ToString() };
        string strSeriesName = "图例1";

        //为x轴指定特定字符串，以便显示数据
        string strXdata = String.Empty;
        foreach (string strData in MonNum)
        {
            strXdata += strData + "\t";
        }
        string strYdata = String.Empty;
        //为y轴指定特定的字符串，以便与x轴相对应
        foreach (string strValue in MonCount)
        {
            strYdata += strValue + "\t";
        }

        //创建ChartSpace对象来放置图表
        ChartSpace laySpace = new ChartSpaceClass();


        //在ChartSpace对象中添加图表
        ChChart InsertChart = laySpace.Charts.Add(0);

        //指定绘制图表的类型。类型可以通过OWC.ChartChartTypeEnum枚举值得到
        //InsertChart.Type = ChartChartTypeEnum.chChartTypeLine;//折线图
        //InsertChart.Type = ChartChartTypeEnum.chChartTypeArea;//面积图
        //InsertChart.Type = ChartChartTypeEnum.chChartTypeBarClustered;//条形图
        //InsertChart.Type = ChartChartTypeEnum.chChartTypeColumnClustered;//柱形图
        InsertChart.Type = ChartChartTypeEnum.chChartTypePie3D;



        laySpace.HasChartSpaceLegend = true;
        laySpace.ChartSpaceLegend.Font.Size = 12;

        laySpace.ChartSpaceLegend.Position = ChartLegendPositionEnum.chLegendPositionRight;
        //指定图表是否需要图例标注
        // InsertChart.HasLegend = false;


        InsertChart.HasTitle = true;//为图表添加标题
        InsertChart.Title.Caption = "";//标题名称

        //为x,y轴添加图示说明
        // InsertChart.Axes[0].HasTitle = true;
        // InsertChart.Axes[0].Title.Caption = "";//月份
        // InsertChart.Axes[1].HasTitle = true;
        //InsertChart.Axes[1].Scaling.SplitMinimum = 200;
        // InsertChart.Axes[1].Title.Caption = "数量";

        //添加一个series系列
        InsertChart.SeriesCollection.Add(0);

        //给定series系列的名字
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimSeriesNames, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strSeriesName);

        //给定分类(图例说明)
        strXdata = strXdata.Substring(0, strXdata.LastIndexOf("\t"));

        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimCategories, +(int)ChartSpecialDataSourcesEnum.chDataLiteral, strXdata);

        //给定值
        InsertChart.SeriesCollection[0].SetData(ChartDimensionsEnum.chDimValues, (int)ChartSpecialDataSourcesEnum.chDataLiteral, strYdata);


        //增加数据值标签
        InsertChart.SeriesCollection[0].DataLabelsCollection.Add();


        // dl.HasValue = true;
        //  dl.HasPercentage = true;
        //图表绘图区的图例放置在右侧。
        //  dl.Position=ChartDataLabelPositionEnum.chLabelPositionRight;

        //显示各部分的数值
        InsertChart.SeriesCollection[0].DataLabelsCollection[0].HasValue = false;
        //显示各部分的百分比
        InsertChart.SeriesCollection[0].DataLabelsCollection[0].HasPercentage = true;


        InsertChart.SeriesCollection[0].Caption = String.Empty;
        InsertChart.SeriesCollection[0].DataLabelsCollection[0].Font.Name = "verdana";
        InsertChart.SeriesCollection[0].DataLabelsCollection[0].Font.Size = 10;
        InsertChart.SeriesCollection[0].DataLabelsCollection[0].Font.Bold = true;
        InsertChart.SeriesCollection[0].DataLabelsCollection[0].Font.Color = "black";
        InsertChart.SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionCenter;
        // InsertChart.SeriesCollection[0].DataLabelsCollection[0].Position = ChartDataLabelPositionEnum.chLabelPositionOutsideEnd;

        //将第三个扇区抽离出来
        //Explosion：返回或设置指定饼图或圆环图扇面的分离程度值。有效范围为 0 到 1000。分离程度值等于图表半径的百分比。
        //Long 类型，可读写。
        InsertChart.SeriesCollection[0].Points[2].Explosion = 45;


        //给第一个扇区设置自定义背景图片
        // objChart.SeriesCollection[0].Points[0].Interior.SetTextured("E:\\Projects\\DotNetNuke\\images\\add.gif", 
        //    OWC11.ChartTextureFormatEnum.chTile,
        //     1,
        //     OWC11.ChartTexturePlacementEnum.chFrontSides);
        //给第二个扇区设置从中心向四周辐射的单色渐变
        InsertChart.SeriesCollection[0].Points[0].Interior.SetOneColorGradient(OWC11.ChartGradientStyleEnum.chGradientFromCenter, OWC11.ChartGradientVariantEnum.chGradientVariantStart, 0.3, "#ba55d3");
        InsertChart.SeriesCollection[0].Points[1].Interior.SetOneColorGradient(OWC11.ChartGradientStyleEnum.chGradientFromCenter, OWC11.ChartGradientVariantEnum.chGradientVariantStart, 0.3, "#9acd32");
        InsertChart.SeriesCollection[0].Points[2].Interior.SetOneColorGradient(OWC11.ChartGradientStyleEnum.chGradientFromCenter, OWC11.ChartGradientVariantEnum.chGradientVariantStart, 0.3, "#a9a9a9");
        InsertChart.SeriesCollection[0].Points[3].Interior.SetOneColorGradient(OWC11.ChartGradientStyleEnum.chGradientFromCenter, OWC11.ChartGradientVariantEnum.chGradientVariantStart, 0.3, "#ff0000");

     
        //给第三个扇区设置倾斜双色渐变
        //objChart.SeriesCollection[0].Points[2].Interior.SetTwoColorGradient(OWC11.ChartGradientStyleEnum.chGradientDiagonalDown,OWC11.ChartGradientVariantEnum.chGradientVariantCenter,"Green","Red");
        //给第四个扇区设置OWC预设的纹理，并设置纹理的背景色为淡绿色，前景色为红色
        //OWC提供了很多纹理，这是其中一种
        //具体的纹理样式可以参看帮助中的ChartPatternTypeEnum枚举
        // objChart.SeriesCollection[0].Points[3].Interior.SetPatterned(OWC11.ChartPatternTypeEnum.chPatternDiagonalBrick,"Red","LightGreen");
        //给第五个扇区设置OWC预设的倾斜，
        //OWC提供了许多种的倾斜，这是其中一种
        //具体的倾斜可以参看帮助中的ChartPresetGradientTypeEnum枚举 
        //   objChart.SeriesCollection[0].Points[4].Interior.SetPresetGradient(OWC11.ChartGradientStyleEnum.chGradientDiagonalUp,OWC11.ChartGradientVariantEnum.chGradientVariantEdges,OWC11.ChartPresetGradientTypeEnum.chGradientGoldII);


        //输出文件.
        string strAbsolutePath = (Server.MapPath("..\\..\\images\\OwcImage\\")) + "ShowData.gif";
        laySpace.ExportPicture(strAbsolutePath, "GIF", 300, 225);

        //创建GIF文件的相对路径.
        string strRelativePath = "../../images/OwcImage/ShowData.gif?rand="+(new Random()).Next();

        //把图片添加到placeholder中，并在页面上显示
        string strImageTag = "<a href=\"./CommunityPlanform.aspx\"><img src='" + strRelativePath + "'" + " border=\"0\" title=\"社区鸟瞰图\"/></a>";

        this.PlaceHolder1.Controls.Add(new LiteralControl(strImageTag));
    }

    /*
    *名称： GetImgCnt
    *功能： 统计数据
    *参数： 无
    *返回： 无
    *说明： 无
    */
    private void GetImgCnt()
    {
        int i = 0, j = 0, l = 0,k=0;

        SalesInfoBean paramBean = new SalesInfoBean();
        paramBean.BuildingNo = hidBuildingNo.Value;

        SalesInfoDao Dao=new SalesInfoDao();
        IList dataList = Dao.FindBySalesInfo(paramBean);

        if (dataList.Count > 0)
        {
            for (int icnt = 0; icnt < dataList.Count; icnt++)
            {
                SalesInfoBean dataBean = new SalesInfoBean();
                dataBean = (SalesInfoBean)dataList[icnt];
                if (dataBean.SNo4 > 0) l++;
                else if (dataBean.SNo3 > 0) i++;
                else if (dataBean.SNo1 > 0) k++;
                else j++;
            }
            SetImage(i, j, l,k);
        }
    }

}
